package org.ch00.test11.demo02;

/*
 *
 *@author XCH
 *@date 2025 - 03 - 11 - 20:09
 *
 */
public class CinemaRunnable extends Thread{
    private int ticketCount = 50; // 总共50张票
    private final Object lock = new Object(); // 用于同步的锁对象

    @Override
    public void run() {
        while (true) {
            synchronized (lock) {
                if (ticketCount <= 0) {
                    break;
                }
                System.out.println(Thread.currentThread().getName() + " 卖出第 " + (50 - ticketCount + 1) + " 张票");
                ticketCount--;
            }
        }
        System.out.println(Thread.currentThread().getName() + " 票已售罄");
    }
}
